package stu.day25_day32.day25.day2;

import stu.day25_day32.day25.all.TreeNode;

import java.util.ArrayList;
import java.util.List;


public class LeetCode94 {
    public List<Integer> inorderTraversal(TreeNode root) {
        ArrayList<Integer> list = new ArrayList<>();
        in(root,list);
        return list;
    }

    public void in(TreeNode node, ArrayList<Integer> list){
        if(node==null){
            return;
        }
        in(node.left,list);
        list.add(node.val);
        in(node.right,list);

    }

    public List<Integer> postorderTraversal(TreeNode root) {
        ArrayList<Integer> list = new ArrayList<>();
        last(root,list);
        return list;
    }
    public void last(TreeNode node, ArrayList<Integer> list){
        if(node==null){
            return;
        }
        last(node.left,list);
        last(node.right,list);
        list.add(node.val);
    }


    public List<Integer> preorderTraversal(TreeNode root) {
        ArrayList<Integer> list = new ArrayList<>();
        pre(root,list);
        return list;
    }
    public void pre(TreeNode node, ArrayList<Integer> list){
        if(node==null){
            return;
        }
        list.add(node.val);
        pre(node.left,list);
        pre(node.right,list);

    }


}
